package com.sysu.ooad.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.sysu.ooad.dao.StudentDao;
import com.sysu.ooad.entity.Course;
import com.sysu.ooad.entity.Student;
import com.sysu.ooad.service.StudentService;

@Component("studentService")
public class StudentServiceImpl implements StudentService {

	private StudentDao studentDao;
	
	public StudentDao getStudentDao() {
		return studentDao;
	}

	@Resource
	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}

	public Student addStudent(String name, String password, Course course) {
		Student student = studentDao.findByName(name);
		if(student != null) return null;
		student = new Student();
		student.setName(name);
		student.setPassword(password);
		student.setCourse(course);
		studentDao.add(student);
		return student;
	}
	
	
	public Student login(String name, String password) {
		Student s = studentDao.findByName(name);
		
		if(s != null && s.getPassword().equals(password)) {
			return s;
		}
		return null;
	}

	public List<Student> findByCourse(Course c) {
		return studentDao.findByCourse(c);
	}

	public List<Student> findWhoHaveNoGroup(Course c) {
		return studentDao.findWhoHaveNoGroup(c);
	}
}
